home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1994 A.D. Software. All Rights Reserved
-
- // OOFTEST6
-
- // this sample modifies related data
- // including demonstrating the caching of related records
- // as would typically be used in a GUI environment
-
- // Simple stream I/O is used to interact with the user.
- #include "oofile.hpp"
-
-
- #include "ooftst02.inc"
-
- int main()
- {
- cout << "OOFILE Validation Suite - Test 6\n"
- << "Simple test to demonstrate updating related fields" << endl
- << "using the database from ooftst02" << endl;
-
- if (dbConnect::fileExists("ooftst06.db"))
- theDB.openConnection("ooftst06.db");
- else {
- theDB.newConnection("ooftst06.db");
- People.AddTest2Data();
- }
-
- dbView smithVisits(People.Visits);
- smithVisits << People.Visits->VisitDate() << People.Visits->Why();
-
- People.search(People.LastName=="Smith");
- cout << "Dumping Smith and his visits: " << endl
- << People << endl
- << smithVisits << endl;
-
- cout << "changing the first reason to 'Computer-Induced Sanity' " << endl;
- People.Visits.gotoRelativeRecord(0);
- People.Visits->Why() = "Computer-Induced Sanity";
-
- cout << "changing the second reason to 'Funny Views' " << endl;
- smithVisits.source()->gotoRelativeRecord(1); // test navigating via the view
- smithVisits.field(1) = "Funny Views";
-
- People.saveRecord(); // save both changes
-
- cout << "Dumping Smith and changed visits: " << endl
- << People << endl
- << smithVisits << endl;
-
- People.AddVisit("14/2/1995", "Anxiety Attacks");
-
- // now change to another related record - our new one should be cached
- smithVisits.source()->gotoRelativeRecord(1);
- smithVisits.field(1) = "Changed Again";
-
- // return to the new record (in the cache) and update it
- smithVisits.source()->gotoRelativeRecord(2);
- smithVisits.field(0) = "15/2/1994";
-
- People.saveRecord();
- cout << "Dumping Smith and visits with added visit: " << endl
- << People << endl
- << smithVisits << endl;
-
- cout << "Now dumping the entire Visits file: " << endl << Visits;
-
- cout << "done" << endl;
-
- return EXIT_SUCCESS;
- }